package com.car.carsharing.controller;

import com.car.carsharing.dto.ResponseDTO;
import com.car.carsharing.dto.TableListDto;
import com.car.carsharing.pojo.Car;
import com.car.carsharing.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class CarController {

    @Autowired
    private CarService carService;

    @RequestMapping("getAllCars")
    public TableListDto getAllCars(@RequestBody Map map){
        return carService.getAllCars(map);
    }

    @RequestMapping("getCar")
    public ResponseDTO getCar(@RequestBody Integer carId){
       Car car = carService.getCarById(carId);
        return new ResponseDTO().success(car,"获得成功");
    }

    @RequestMapping("addCar")
    public ResponseDTO addCar(@RequestBody Car car){
        int r = carService.addCar(car);
        return new ResponseDTO().success("新增成功");
    }

    @RequestMapping("updateCar")
    public ResponseDTO updateCar(@RequestBody Car car){
        int r = carService.updateCar(car);
        return new ResponseDTO().success("修改成功");
    }

    @RequestMapping("getCarNum")
    public ResponseDTO getCarNum(){
        List<Car> cars = carService.getCarNum();
        return new ResponseDTO().success(cars,"获取成功");
    }
}
